@scrider/formatter 1.4.1 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +99 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -4
- package/dist/index.d.ts +38 -4
- package/dist/index.js +90 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -36,13 +36,20 @@ __export(index_exports, {
|
|
|
36
36
|
BOX_OVERFLOW_VALUES: () => BOX_OVERFLOW_VALUES,
|
|
37
37
|
BlockHandlerRegistry: () => BlockHandlerRegistry,
|
|
38
38
|
BrowserDOMAdapter: () => BrowserDOMAdapter,
|
|
39
|
+
LINE_HEIGHT_BLOCK_TAGS: () => LINE_HEIGHT_BLOCK_TAGS,
|
|
39
40
|
NODE_TYPE: () => NODE_TYPE,
|
|
40
41
|
NodeDOMAdapter: () => NodeDOMAdapter,
|
|
42
|
+
PARAGRAPH_SPACING_BLOCK_TAGS: () => PARAGRAPH_SPACING_BLOCK_TAGS,
|
|
41
43
|
Registry: () => Registry,
|
|
44
|
+
SCRIDER_LINE_HEIGHT_KEY: () => SCRIDER_LINE_HEIGHT_KEY,
|
|
45
|
+
SCRIDER_MARGIN_AFTER_KEY: () => SCRIDER_MARGIN_AFTER_KEY,
|
|
42
46
|
alertBlockHandler: () => alertBlockHandler,
|
|
43
47
|
alignFormat: () => alignFormat,
|
|
44
48
|
backgroundFormat: () => backgroundFormat,
|
|
45
49
|
blockFormat: () => blockFormat,
|
|
50
|
+
blockLineHeightStyleParts: () => blockLineHeightStyleParts,
|
|
51
|
+
blockMarginAfterStyleParts: () => blockMarginAfterStyleParts,
|
|
52
|
+
blockPresentationStyleParts: () => blockPresentationStyleParts,
|
|
46
53
|
blockquoteFormat: () => blockquoteFormat,
|
|
47
54
|
boldFormat: () => boldFormat,
|
|
48
55
|
boxBlockHandler: () => boxBlockHandler,
|
|
@@ -93,6 +100,8 @@ __export(index_exports, {
|
|
|
93
100
|
markdownToDeltaSync: () => markdownToDeltaSync,
|
|
94
101
|
nodeAdapter: () => nodeAdapter,
|
|
95
102
|
normalizeDelta: () => normalizeDelta,
|
|
103
|
+
parseScriderLineHeightMultiplier: () => parseScriderLineHeightMultiplier,
|
|
104
|
+
parseScriderMarginAfterEm: () => parseScriderMarginAfterEm,
|
|
96
105
|
preloadRemark: () => preloadRemark,
|
|
97
106
|
resolveDocumentPresentation: () => resolveDocumentPresentation,
|
|
98
107
|
resolveTablePresentation: () => resolveTablePresentation,
|
|
@@ -2603,39 +2612,100 @@ function slugifyWithDedup(text, usedSlugs) {
|
|
|
2603
2612
|
return `${base}-${count}`;
|
|
2604
2613
|
}
|
|
2605
2614
|
|
|
2615
|
+
// src/conversion/html/block-presentation.ts
|
|
2616
|
+
var SCRIDER_LINE_HEIGHT_KEY = "scrider-line-height";
|
|
2617
|
+
var SCRIDER_MARGIN_AFTER_KEY = "scrider-margin-after";
|
|
2618
|
+
var LINE_HEIGHT_BLOCK_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
|
|
2619
|
+
var PARAGRAPH_SPACING_BLOCK_TAGS = /* @__PURE__ */ new Set(["p"]);
|
|
2620
|
+
function parseScriderLineHeightMultiplier(value) {
|
|
2621
|
+
const trimmed = value.trim();
|
|
2622
|
+
if (!trimmed) return void 0;
|
|
2623
|
+
if (trimmed.endsWith("%")) {
|
|
2624
|
+
const pct = Number.parseFloat(trimmed.slice(0, -1));
|
|
2625
|
+
if (Number.isFinite(pct) && pct > 0) return pct / 100;
|
|
2626
|
+
return void 0;
|
|
2627
|
+
}
|
|
2628
|
+
const n = Number.parseFloat(trimmed);
|
|
2629
|
+
if (Number.isFinite(n) && n > 0) return n;
|
|
2630
|
+
return void 0;
|
|
2631
|
+
}
|
|
2632
|
+
function lineHeightStyleParts(multiplier) {
|
|
2633
|
+
const pct = Math.round(multiplier * 100);
|
|
2634
|
+
return [`line-height:${multiplier}`, `mso-line-height-alt:${pct}%`];
|
|
2635
|
+
}
|
|
2636
|
+
function blockLineHeightStyleParts(tag, blockAttributes, resolved) {
|
|
2637
|
+
if (!LINE_HEIGHT_BLOCK_TAGS.has(tag)) return [];
|
|
2638
|
+
const raw = blockAttributes?.[SCRIDER_LINE_HEIGHT_KEY];
|
|
2639
|
+
if (typeof raw === "string") {
|
|
2640
|
+
const fromBlock = parseScriderLineHeightMultiplier(raw);
|
|
2641
|
+
if (fromBlock !== void 0) return lineHeightStyleParts(fromBlock);
|
|
2642
|
+
}
|
|
2643
|
+
if (resolved?.lineSpacing !== void 0) {
|
|
2644
|
+
return lineHeightStyleParts(resolved.lineSpacing);
|
|
2645
|
+
}
|
|
2646
|
+
return [];
|
|
2647
|
+
}
|
|
2648
|
+
function parseScriderMarginAfterEm(value) {
|
|
2649
|
+
const trimmed = value.trim();
|
|
2650
|
+
if (!trimmed) return void 0;
|
|
2651
|
+
const emMatch = trimmed.match(/^(-?\d+(?:\.\d+)?)\s*em$/i);
|
|
2652
|
+
if (emMatch) {
|
|
2653
|
+
const n2 = Number.parseFloat(emMatch[1]);
|
|
2654
|
+
if (Number.isFinite(n2) && n2 >= 0) return n2;
|
|
2655
|
+
return void 0;
|
|
2656
|
+
}
|
|
2657
|
+
const n = Number.parseFloat(trimmed);
|
|
2658
|
+
if (Number.isFinite(n) && n >= 0) return n;
|
|
2659
|
+
return void 0;
|
|
2660
|
+
}
|
|
2661
|
+
function marginAfterStyleParts(em) {
|
|
2662
|
+
return [`margin-top:0`, `margin-bottom:${em}em`];
|
|
2663
|
+
}
|
|
2664
|
+
function blockMarginAfterStyleParts(tag, blockAttributes, resolved) {
|
|
2665
|
+
if (!PARAGRAPH_SPACING_BLOCK_TAGS.has(tag)) return [];
|
|
2666
|
+
const raw = blockAttributes?.[SCRIDER_MARGIN_AFTER_KEY];
|
|
2667
|
+
if (typeof raw === "string") {
|
|
2668
|
+
const fromBlock = parseScriderMarginAfterEm(raw);
|
|
2669
|
+
if (fromBlock !== void 0) return marginAfterStyleParts(fromBlock);
|
|
2670
|
+
}
|
|
2671
|
+
if (resolved?.paragraphSpacingAfterEm !== void 0) {
|
|
2672
|
+
return marginAfterStyleParts(resolved.paragraphSpacingAfterEm);
|
|
2673
|
+
}
|
|
2674
|
+
return [];
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2606
2677
|
// src/conversion/html/document-presentation.ts
|
|
2607
2678
|
function resolveDocumentPresentation(presentation) {
|
|
2608
2679
|
if (!presentation) return void 0;
|
|
2609
2680
|
const lineSpacing = typeof presentation.lineSpacing === "number" && presentation.lineSpacing > 0 ? presentation.lineSpacing : void 0;
|
|
2610
2681
|
const textIndentCm = typeof presentation.textIndentCm === "number" && presentation.textIndentCm > 0 ? presentation.textIndentCm : void 0;
|
|
2611
2682
|
const listBlockIndentCm = typeof presentation.listBlockIndentCm === "number" && presentation.listBlockIndentCm > 0 ? presentation.listBlockIndentCm : void 0;
|
|
2612
|
-
|
|
2683
|
+
const paragraphSpacingAfterEm = typeof presentation.paragraphSpacingAfterEm === "number" && Number.isFinite(presentation.paragraphSpacingAfterEm) && presentation.paragraphSpacingAfterEm >= 0 ? presentation.paragraphSpacingAfterEm : void 0;
|
|
2684
|
+
if (lineSpacing === void 0 && paragraphSpacingAfterEm === void 0 && textIndentCm === void 0 && listBlockIndentCm === void 0) {
|
|
2613
2685
|
return void 0;
|
|
2614
2686
|
}
|
|
2615
|
-
return { lineSpacing, textIndentCm, listBlockIndentCm };
|
|
2687
|
+
return { lineSpacing, paragraphSpacingAfterEm, textIndentCm, listBlockIndentCm };
|
|
2616
2688
|
}
|
|
2617
|
-
var LINE_HEIGHT_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
|
|
2618
2689
|
var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p"]);
|
|
2619
2690
|
function documentPresentationListWrapperStyleParts(resolved) {
|
|
2620
2691
|
if (!resolved?.listBlockIndentCm) return [];
|
|
2621
|
-
return [
|
|
2622
|
-
`padding-left:1.25em`,
|
|
2623
|
-
`margin-left:${resolved.listBlockIndentCm}cm`
|
|
2624
|
-
];
|
|
2692
|
+
return [`padding-left:1.25em`, `margin-left:${resolved.listBlockIndentCm}cm`];
|
|
2625
2693
|
}
|
|
2626
2694
|
function documentPresentationStyleParts(tag, resolved) {
|
|
2627
2695
|
if (!resolved) return [];
|
|
2628
2696
|
const parts = [];
|
|
2629
|
-
if (resolved.lineSpacing !== void 0 && LINE_HEIGHT_TAGS.has(tag)) {
|
|
2630
|
-
const pct = Math.round(resolved.lineSpacing * 100);
|
|
2631
|
-
parts.push(`line-height:${resolved.lineSpacing}`);
|
|
2632
|
-
parts.push(`mso-line-height-alt:${pct}%`);
|
|
2633
|
-
}
|
|
2634
2697
|
if (resolved.textIndentCm !== void 0 && TEXT_INDENT_TAGS.has(tag)) {
|
|
2635
2698
|
parts.push(`text-indent:${resolved.textIndentCm}cm`);
|
|
2636
2699
|
}
|
|
2637
2700
|
return parts;
|
|
2638
2701
|
}
|
|
2702
|
+
function blockPresentationStyleParts(tag, blockAttributes, resolved) {
|
|
2703
|
+
return [
|
|
2704
|
+
...blockLineHeightStyleParts(tag, blockAttributes, resolved),
|
|
2705
|
+
...blockMarginAfterStyleParts(tag, blockAttributes, resolved),
|
|
2706
|
+
...documentPresentationStyleParts(tag, resolved)
|
|
2707
|
+
];
|
|
2708
|
+
}
|
|
2639
2709
|
function joinStyleParts(parts) {
|
|
2640
2710
|
return parts.length > 0 ? ` style="${parts.join("; ")}"` : "";
|
|
2641
2711
|
}
|
|
@@ -2782,6 +2852,7 @@ function deltaToHtml(delta, options = {}) {
|
|
|
2782
2852
|
html += renderListItem(
|
|
2783
2853
|
content,
|
|
2784
2854
|
listItemAttrs,
|
|
2855
|
+
line.attributes,
|
|
2785
2856
|
pretty,
|
|
2786
2857
|
indentLevel,
|
|
2787
2858
|
hierarchicalNumber,
|
|
@@ -3101,17 +3172,14 @@ function getListItemAttributes(attributes) {
|
|
|
3101
3172
|
}
|
|
3102
3173
|
return "";
|
|
3103
3174
|
}
|
|
3104
|
-
function renderListItem(content, attrs, pretty, indentLevel, hierarchicalNumber, resolvedDocumentPresentation) {
|
|
3175
|
+
function renderListItem(content, attrs, blockAttributes, pretty, indentLevel, hierarchicalNumber, resolvedDocumentPresentation) {
|
|
3105
3176
|
const indent = pretty ? getIndent(indentLevel) : "";
|
|
3106
3177
|
const innerContent = content || "<br>";
|
|
3107
3178
|
let fullAttrs = attrs;
|
|
3108
3179
|
if (hierarchicalNumber) {
|
|
3109
3180
|
fullAttrs += ` data-number="${hierarchicalNumber}"`;
|
|
3110
3181
|
}
|
|
3111
|
-
|
|
3112
|
-
documentPresentationStyleParts("li", resolvedDocumentPresentation)
|
|
3113
|
-
);
|
|
3114
|
-
fullAttrs += styleAttr;
|
|
3182
|
+
fullAttrs += getBlockStyleAttribute("li", blockAttributes, resolvedDocumentPresentation);
|
|
3115
3183
|
const html = `${indent}<li${fullAttrs}>${innerContent}</li>`;
|
|
3116
3184
|
return pretty ? html + "\n" : html;
|
|
3117
3185
|
}
|
|
@@ -3123,7 +3191,11 @@ function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPrese
|
|
|
3123
3191
|
return pretty ? html + "\n" : html;
|
|
3124
3192
|
}
|
|
3125
3193
|
function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
|
|
3126
|
-
const styles =
|
|
3194
|
+
const styles = blockPresentationStyleParts(
|
|
3195
|
+
tag,
|
|
3196
|
+
attributes,
|
|
3197
|
+
resolvedDocumentPresentation
|
|
3198
|
+
);
|
|
3127
3199
|
if (attributes) {
|
|
3128
3200
|
const alignVal = attributes.align;
|
|
3129
3201
|
if (alignVal && typeof alignVal === "string" && alignVal !== "left") {
|
|
@@ -5263,13 +5335,20 @@ function extractTableRegion(ops, hintOpIdx) {
|
|
|
5263
5335
|
BOX_OVERFLOW_VALUES,
|
|
5264
5336
|
BlockHandlerRegistry,
|
|
5265
5337
|
BrowserDOMAdapter,
|
|
5338
|
+
LINE_HEIGHT_BLOCK_TAGS,
|
|
5266
5339
|
NODE_TYPE,
|
|
5267
5340
|
NodeDOMAdapter,
|
|
5341
|
+
PARAGRAPH_SPACING_BLOCK_TAGS,
|
|
5268
5342
|
Registry,
|
|
5343
|
+
SCRIDER_LINE_HEIGHT_KEY,
|
|
5344
|
+
SCRIDER_MARGIN_AFTER_KEY,
|
|
5269
5345
|
alertBlockHandler,
|
|
5270
5346
|
alignFormat,
|
|
5271
5347
|
backgroundFormat,
|
|
5272
5348
|
blockFormat,
|
|
5349
|
+
blockLineHeightStyleParts,
|
|
5350
|
+
blockMarginAfterStyleParts,
|
|
5351
|
+
blockPresentationStyleParts,
|
|
5273
5352
|
blockquoteFormat,
|
|
5274
5353
|
boldFormat,
|
|
5275
5354
|
boxBlockHandler,
|
|
@@ -5320,6 +5399,8 @@ function extractTableRegion(ops, hintOpIdx) {
|
|
|
5320
5399
|
markdownToDeltaSync,
|
|
5321
5400
|
nodeAdapter,
|
|
5322
5401
|
normalizeDelta,
|
|
5402
|
+
parseScriderLineHeightMultiplier,
|
|
5403
|
+
parseScriderMarginAfterEm,
|
|
5323
5404
|
preloadRemark,
|
|
5324
5405
|
resolveDocumentPresentation,
|
|
5325
5406
|
resolveTablePresentation,
|